package com.szrt.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.szrt.base.DBUtil;
import com.szrt.dao.UserDao;
import com.szrt.dto.PageDTO;
import com.szrt.entity.UserEntity;

public class UserDaoImpl implements UserDao {
	
	/**
	 * 分页
	 */
	@Override
	public List<UserEntity> fingWithPage(PageDTO page) throws Exception {
		
		Connection conn = DBUtil.getConn();
		String sql ="SELECT ID AS id,NAME AS name,PASSWORD AS password FROM oa_user_t LIMIT ?,?";
		PreparedStatement ps = conn.prepareStatement(sql);
		
		//(page.getCurrentPage()-1)*page.getPageSize()
		ps.setInt(1,(page.getCurrentPage()-1)*page.getPageSide());
		ps.setInt(2,page.getPageSide());
		ResultSet rs = ps.executeQuery();
		List<UserEntity> listEntity=new ArrayList<UserEntity>();
		while(rs.next()){
			UserEntity entity=new UserEntity();
			entity.setId(rs.getInt("id"));
			entity.setName(rs.getString("name"));
			entity.setPassword(rs.getString("password"));
			listEntity.add(entity);
		}
		
		return listEntity;
	}

	@Override
	public int deleteById(Integer did) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}

	

}
